﻿using System.Collections.Generic;
using System.Linq;
using Citi.ReportManager.Domain;

namespace Citi.ReportManager.WebUi.Models
{
    public class ReportModel
    {
        public ReportModel(Category category, string folder)
        {
            CurrentCategory = new CategoryModel().CreateModel(category);
            CurrentFolder = new CurrentFolderModel(folder);

            var parentNumber = 0;
            BreadCrumbs = new List<ReportItemModel>();
            var currentCategory = category;

            while (currentCategory != null && parentNumber < 5)
            {
                BreadCrumbs.Add(new ReportItemModel { CategoryId = currentCategory.Id, Name = currentCategory.Name });
                currentCategory = currentCategory.Parent;
            }

            if (folder == null) return;

            var path = string.Empty;

            foreach (var item in CurrentFolder.Path.Split(new[] { '\\' }))
            {
                path += string.IsNullOrEmpty(path) ? item : string.Concat(@"\", item);
                BreadCrumbs.Insert(0, new ReportItemModel { CategoryId = category.Id, Name = item, PathDownload = path });
            }
        }

        public int CurrentReportFolderId { get; set; }
        public CategoryModel CurrentCategory { get; set; }
        public List<ReportItemModel> BreadCrumbs { get; set; }
        public CurrentFolderModel CurrentFolder { get; set; }
        public List<ReportItemModel> Items { get; set; }
    }
}